<template>
  <div class="page">
    <a v-show="!ishome" class="page-prev page-icon" @click="prevjump"></a>
    <div class="page-box">
      <a v-show="!ishome" class="page-home" @click="homejump">首页</a>
      <ul class="page-list">
        <li @click="pagejump" v-for="n in pagenum">{{n}}</li>
      </ul>
      <a v-show="!isend" class="page-end" @click="lastjump">最后一页</a>
    </div>
    <a v-show="!isend" @click="nextjump" class="page-next page-icon"></a>
  </div>
</template>
<script>
	export default{
	  name:'Page',
	  props:{
	    total:{
	      //总数
	      default:1
	    },
	    limit:{
	      //每页数量
	      default:10
	    }
	  },
	  data(){
	    return{
	      currentpage:this.$route.params.page,
	      container:'',
	    }
	  },methods:{
	    pagejump(event){
	      var _page = event.currentTarget.innerText;
  	      this.ishome = _page>1?false:true;
  	      pageselecte(this,_page);
	    },
	    prevjump(){
	      this.currentpage =this.currentpage*1-1;
	      pageselecte(this);
	    },
      nextjump(){
        this.currentpage =this.currentpage*1+1;
        pageselecte(this);
      },
      lastjump(){
        this.currentpage = this.pagenum;
        pageselecte(this);
      },homejump(){
        this.currentpage = 1;
        pageselecte(this);
      }
	  },mounted(){
	    var self = this;
	    this.container = $(".page-list");
	    $(".page-list").children("li:eq("+(self.currentpage-1)+")").addClass("selected");
	  },computed:{
	    pagenum(){
	      return (this.total/this.limit)<1?1:(this.total/this.limit)
	    },ishome(){
	      return this.currentpage>1?false:true
	    },
	    isend(){
	      return this.pagenum>this.currentpage?false:true
	    }
	  }
	}
    
    function pageselecte(t,page){
      t.container.children(".selected").removeClass("selected");
      t.container.children("li:eq("+(t.currentpage-1)+")").addClass("selected");
      location.href="#/information/page/"+t.currentpage;
    }
</script>
<style scoped>
  .page{
    height: 40px;
    overflow: hidden;
    background: #EDEDED;
    padding: 10px 40px;
    -moz-user-select: none;
    -webkit-user-select: none;
  }
  .page a{
    font-size: 14px;
    vertical-align: top;
    text-decoration: none;
    line-height: 40px;
    color: #666;
    display: inline-block;
  }
  .page-prev{
    float: left;
  }
  .page-next{
    float: right;
  }
  .page-prev img,.page-next img{
    width: 40px;
  }
  .page-box{
    text-align: center;
    position: absolute;
    left: 80px;
    right: 80px;
    overflow: hidden;
  }
  .page-list{
    display: inline-block;
    width: auto;
    overflow: hidden;margin: 0 10px;
  }
  .page-list li{
    -webkit-user-select: none;-moz-user-select: none;
    display: inline-block;float: left;line-height: 40px;color: #666;
    margin: 0 3px;padding: 0 3px;
  }.page-list li.selected{
    color: #1189B5;
  }
  .page-list li:hover,a:hover{color: #1189B5;cursor: pointer;}
  .page-icon{
    width: 40px;
    background: url('../assets/img/pageicon.png') no-repeat;
  }
.page-next:hover{width:41px;height:40px;background-position:-0px -0px;}
.page-next{width:41px;height:40px;background-position:-43px -0px;}
.page-prev:hover{width:41px;height:40px;background-position:-0px -42px;}
.page-prev{width:41px;height:40px;background-position:-43px -42px;}
</style>